package cn.com.huzo.repository.tech.impl;

import cn.com.huzo.model.entities.tech.ProductBomHeaderEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import cn.com.huzo.repository.tech.ProductBomHeaderRepository;

/**
 * EBOM数据访问对象。
 *
 * @author 吴旭
 */
@Repository("ProductBomHeaderRepository")
public class ProductBomHeaderRepositoryImpl extends GenericRepositoryImpl<ProductBomHeaderEntity, Long>
        implements ProductBomHeaderRepository {

    private final String namespace = "cn.com.huzo.repository.tech.ProductBomHeaderRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public ProductBomHeaderRepositoryImpl() {
        super(ProductBomHeaderEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ProductBomHeaderEntity fetchByKey(Long key) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", key);

        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByKey"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<ProductBomHeaderEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Long insert(ProductBomHeaderEntity instance) {
        // 影响的行数
        getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), instance);

        // 返回出入后的记录ID
        return instance.getHeaderId();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer update(ProductBomHeaderEntity instance) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "update"), instance);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLastUpdatedDate(Long headerId) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLastUpdatedDate"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(Long key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }
}
